//
//  WMEImageViewController.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/2/29.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEImageViewController.h"
#import <UIImageView+WebCache.h>

@interface WMEImageViewController ()
@property (nonatomic, retain)UIScrollView *scrollView;
@end

@implementation WMEImageViewController
- (void)dealloc
{
    [_scrollView release];
    [_imgStr release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
//    self.tabBarController.hidesBottomBarWhenPushed = YES;
    if (_width.integerValue != 0) {
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 -49)];
        _scrollView.backgroundColor = [UIColor blackColor];
        [self.view addSubview:_scrollView];
        _scrollView.contentSize = CGSizeMake(WIDTH, WIDTH * _height.integerValue / _width.integerValue);
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, WIDTH * _height.integerValue / _width.integerValue)];
        //    img.center = self.view.center;
        img.contentMode = UIViewContentModeScaleAspectFit;
        
        img.clipsToBounds = YES;
        [img sd_setImageWithURL:[NSURL URLWithString:_imgStr]];
        [self.scrollView addSubview:img];
        [_scrollView release];
        [img release];
    }else{
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        _scrollView.backgroundColor = [UIColor blackColor];
        [self.view addSubview:_scrollView];
//        _scrollView.contentSize = CGSizeMake(WIDTH, WIDTH);
        UIImageView *img = [[UIImageView alloc] init];
        [img sd_setImageWithURL:[NSURL URLWithString:_imgStr]];
        CGFloat imgHeight = img.image.size.height;
        CGFloat imgWidth = img.image.size.width;
        img.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width * imgHeight / imgWidth);

        img.center = self.view.center;
        img.contentMode = UIViewContentModeScaleAspectFit;
        img.clipsToBounds = YES;
        _scrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.width * imgHeight / imgWidth);
        [self.scrollView addSubview:img];
        [_scrollView release];
        [img release];

//        UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//        [imgView sd_setImageWithURL:[NSURL URLWithString:_imgStr]];
//        imgView.contentMode = UIViewContentModeScaleAspectFit;
//        imgView.clipsToBounds = YES;
//
//        [self.view addSubview:imgView];
    }
}
//-(void)setImgStr:(NSString *)imgStr
//{
//    if (_imgStr != imgStr) {
//        [_imgStr release];
//        _imgStr = [imgStr retain];
//        [_img sd_setImageWithURL:[NSURL URLWithString:_imgStr]];
//    }
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
